package com.office;

import com.google.common.io.Files;
import com.office.util.OfficeTransitionPdfUtil;
import com.office.util.ReadFileImageUtil;
import com.office.util.ReadFileTextUtil;
import com.watermark.util.WriteImageWatermarkUtil;
import org.apache.tika.exception.TikaException;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * 用于提供*
 * @author tianyf
 */
public class OfficeTest {

    public static void main(String[] args) {

        //测试 word excel ppt pdf text 文件的 文字读取
//        testReadFileText();

        //测试读取 ppt 图片信息
//        testReadPPTPicture();

        //测试读取 word 图片信息
//        testReadWordPicture();

        //测试读取 pdf图片信息
        testReadPdfPicture();

        //测试 图片 打 水印
//        testWritePictureWatermark();

        //测试office文档转pdf
//        testOfficeTransitionPdf();
    }

    /**
     * 以下八种文件 可以正常读取文字*
     * xls xlsx 存在读取 sheet1 sheet2 的情况*
     */
    private static void testReadFileText() {
        File xls = new File("C:\\testFile\\测试Excel.xls");
        File xlsx = new File("C:\\testFile\\测试Excel.xlsx");
        File ppt = new File("C:\\testFile\\测试PPT.ppt");
        File pptx = new File("C:\\testFile\\测试PPT.pptx");
        File txt = new File("C:\\testFile\\测试Text.txt");
        File md = new File("C:\\testFile\\测试md.md");
        File doc = new File("C:\\testFile\\测试Word.doc");
        File docx = new File("C:\\testFile\\测试Word.docx");

        try {
            String text = ReadFileTextUtil.readOffice(docx);
            System.out.println("打印文件解析出来的文字："+text);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TikaException e) {
            e.printStackTrace();
        }
    }

    /**
     * 测试读取ppt的图片信息 并持久化至相关路径 *
     */
    private static void testReadPPTPicture() {
        File ppt = new File("C:\\testFile\\测试PPT.ppt");
        File pptx = new File("C:\\testFile\\测试PPT.pptx");
        try {
            byte[] bytes = Files.toByteArray(pptx);
            List<File> files = ReadFileImageUtil.readPPTxPicture(bytes);
            System.out.println(files);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 测试读取Wrod中图片信息*
     */
    private static void testReadWordPicture(){
        File doc = new File("C:\\testFile\\测试Word.doc");
        try {
            byte[] bytes = Files.toByteArray(doc);
            List<File> files = ReadFileImageUtil.readDocPicture(bytes);
            System.out.println(files);
        } catch (IOException e) {
            e.printStackTrace();
        }

        File docx = new File("C:\\testFile\\测试Word.docx");
        try {
            byte[] bytes = Files.toByteArray(docx);
            List<File> files = ReadFileImageUtil.readDocxPicture(bytes);
            System.out.println(files);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 测试 读取pdf图片信息*
     */
    private static void testReadPdfPicture(){
        File docx = new File("C:\\Users\\10259\\Desktop\\翌智\\需求文档整理\\project妇幼项目\\妇幼BIM图纸数据\\01 建筑 - 副本\\01 建筑PDF\\建筑-0-A-01-01-建筑施工图设计说明（一）.pdf");
        try {
            byte[] bytes = Files.toByteArray(docx);
            List<File> files = ReadFileImageUtil.readPdfPicture(bytes);
            System.out.println(files);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    /**
     * 测试office转pdf*
     */
    private static void testOfficeTransitionPdf(){
        //不支持md文件
        File md = new File("C:\\testFile\\测试md.md");

        //以下类型文件全部支持
        File xls = new File("C:\\testFile\\测试Excel.xls");
        File xlsx = new File("C:\\testFile\\测试Excel.xlsx");
        File ppt = new File("C:\\testFile\\测试PPT.ppt");
        File pptx = new File("C:\\testFile\\测试PPT.pptx");
        File txt = new File("C:\\testFile\\测试Text.txt");
        File doc = new File("C:\\testFile\\测试Word.doc");
        File docx = new File("C:\\testFile\\测试Word.docx");

        OfficeTransitionPdfUtil.officeTranstionPdf(docx);

    }
}
